package hhs.poc.activities.whoiswho;

import hhs.poc.util.utils;

import java.util.ArrayList;

import android.R;
import android.R.drawable;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.PaintDrawable;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.View.OnKeyListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

public class SpinAdapter extends ArrayAdapter<String> {
	Context context;
	ArrayList<Employee> values;
	ArrayList<String> strings;
	Intent i;

	public SpinAdapter(Context context, int textViewResourceId,
			ArrayList<Employee> values, ArrayList<String> strings) {
		super(context, textViewResourceId, strings);
		this.context = context;
		this.values = values;
		this.strings = strings;
	}

	public void setIntent(Intent i) {
		this.i = i;
	}

	public int getLastIndex() {
		int index = values.size() - 1;
		return index;
	}

	public Employee getEmployee(int position) {
		Employee emp = values.get(position);
		return emp;
	}

	public String getItem(int position) {
		String str = strings.get(position);
		return str;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		TextView view = new TextView(context);

		view.setText(values.get(position).getName());
		view.setTextColor(Color.BLACK);
		view.setPadding(7, 15, 7, 15);
		view.setTextSize(16);

		view.setOnTouchListener(new OnTouchListener() {

			public boolean onTouch(View v, MotionEvent event) {
				int action = event.getAction();
				if (action == MotionEvent.ACTION_DOWN) {
					v.setBackgroundColor(Color.parseColor("#fb9f03"));
				} else {
					v.setBackgroundColor(Color.WHITE);
				}
				return false;
			}
		});

		view.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Employee emp = getEmployee(position);
				utils.saveEmployee(emp);
				context.startActivity(i);
			}
		});

		return view;
	}

	@Override
	public View getDropDownView(int position, View convertView, ViewGroup parent) {
		return getView(position, convertView, parent);
	}
}
